home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / spoc88 / edt / testdays.pas < prev   
Pascal/Delphi Source File  |  1988-06-08  |  1KB  |  67 lines

  1. program TestDays;
  2.  
  3. uses CRT; { for ClrScr, GoToXY, ClrEol }
  4.  
  5. type
  6.   Days       = (Sun, Mon, Tues, Wed, Thurs, Fri, Sat, endDay);
  7.  
  8. const
  9.   DayName    : array[Days] of string[5]
  10.   = ('Sun','Mon','Tues','Wed','Thurs','Fri','Sat','');
  11.  
  12. var
  13.   Today,Tomorrow : Days;
  14.  
  15.  
  16. function ToUpper(S : string) : string;
  17.  
  18. var
  19.   I,Len       : word;
  20.   Ch          : char;
  21.  
  22. begin
  23.   Len := Length(S);
  24.   for I := 1 to Len do begin
  25.     Ch := S[I];
  26.     if ('a' <= Ch) and (Ch <= 'z')
  27.       then S[I] := Chr(Ord(Ch)-32)
  28.   end;
  29.   ToUpper := S
  30. end; { of func ToUpper }
  31.  
  32.  
  33. function GetDay(Prompt : string) : Days;
  34. {
  35.    writes out Prompt at (1,1) -- continues to prompt until
  36.    the user enters a valid day name (Sun..Sat); case doesn't
  37.    matter -- returns the day value entered
  38. }
  39.  
  40. var
  41.   Ans        : string[5];
  42.   Day        : Days;
  43.  
  44. begin
  45.   repeat
  46.     GoToXY(1,1); ClrEol;
  47.     Write(Prompt);
  48.     Readln(Ans);
  49.     Ans := ToUpper(Ans);
  50.     Day := Sun;
  51.     while (Day <= Sat) and (Ans <> ToUpper(DayName[Day])) do
  52.       Day := Succ(Day)
  53.   until Day <> endDay;
  54.   GetDay := Day
  55. end; { of func GetDay }
  56.  
  57.  
  58. begin { main body }
  59.   ClrScr;
  60.   Today := GetDay('Which day of the week is today? ');
  61.   Tomorrow := Succ(Today);
  62.   if Tomorrow = endDay
  63.     then Tomorrow := Sun;
  64.   Writeln('Tomorrow is : ',DayName[Tomorrow])
  65. end. { of program TestDays }
  66.  
  67.